﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
    <style>

        #organization-tree {
            width: 100% !important;
            height: -webkit-calc(100vh - 95px);
            height: -moz-calc(100vh - 95px);
            height: calc(100vh - 95px);
        }

        #newcategory-detail {
            width: 100% !important;
            height: -webkit-calc(100vh - 86px);
            height: -moz-calc(100vh - 86px);
            height: calc(100vh - 86px);
            overflow: auto;
            padding-right: 5px;
        }

        .bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            border-top: 1px solid #eee;
            background-color: #fff;
        }
        .layoutrow {
            display: flex;
            justify-items: left;
            margin-bottom: 10px;
        }

        .layout-title {
            padding: 0px 8px;
            font-size: 14px;
            flex: 0 0 150px;
        }

        .layout-content {
            padding: 0px 8px;
            text-align: left;
        }
        #organization-tree-empty{
             text-align:center;
        }
    </style>
}

<div class="layui-row layui-col-space15">
    <div class="layui-col-md5">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-row" style="margin-bottom:15px;">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="orgname" placeholder="" class="layui-input">
                    </div>
                    <button type="button" class="pear-btn pear-btn-md pear-btn-primary" id="btn_TreeFuzzySearch">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                </div>
                <div style="overflow: auto" class="divscrollbar">
                    <ul id="organization-tree-empty" class="layui-hide">没有匹配数据</ul>
                    <ul id="organization-tree" class="dtree" data-id="-1"></ul>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md7">
        <div class="layui-card">
            <div class="layui-card-header">部门详情 
                    @{
                    await Html.RenderPartialAsync("_ToolbarAuthTpl", new SystemFunctionModel
                        {
                            MenuKey = SysMenuConstant.MENU_ORGANIZE_MANAGE,
                            FunDictionary = new Dictionary<string, string> { { "Add", "新增" } }
                        });
                }</div>
            <div class="layui-card-body">
                <div id="newcategory-detail" class="divscrollbar">
                    <blockquote class="layui-elem-quote">
                        选择左侧的部门进行相关操作。
                    </blockquote>
                    <div class="layui-form " style="padding: 15px 0 0 0;">
                        <input type="hidden" name="Id" value="" />
                        <input type="hidden" id="ParentId" name="ParentId" value="" />

                        <div class="layoutrow" style="display:none;">
                            <div class="layout-title">父级部门</div><div class="layout-content" id="ParentTitle"></div>
                        </div>
                        <hr>
                        <div class="layoutrow">
                            <div class="layout-title">部门名称</div><div class="layout-content" ><span id="OrgName"></span> </div>
                        </div>
                        <hr>
                        <div class="layoutrow">
                            <div class="layout-title">部门编码</div><div class="layout-content" id="OrgCode"></div>
                        </div>
                        
                        <div class="layoutrow layui-hide">
                            <div class="layout-title">注册公司名称</div><div class="layout-content" id="OrgCompanyName"></div>
                        </div>
                        
                        <div class="layoutrow layui-hide">
                            <div class="layout-title">法人代表</div><div class="layout-content" id="Corporate"></div>
                        </div>
                        <hr>
                        <div class="layoutrow">
                            <div class="layout-title">负责人人&电话</div><div class="layout-content" id="TelephoneContact"></div>
                        </div>
                       <hr>
                        <div class="layoutrow layui-hide">
                            <div class="layout-title">联系人&电话</div><div class="layout-content" id="TelephoneContact1"></div>
                        </div>
                       
                        <div class="layoutrow layui-hide">
                            <div class="layout-title">联系人&电话</div><div class="layout-content" id="TelephoneContact2"></div>
                        </div>
                       
                        <div class="layoutrow layui-hide">
                            <div class="layout-title">注册地址</div><div class="layout-content" id="Addr"></div>
                        </div>
                       
                        <div class="layoutrow">
                            <div class="layout-title">附件列表</div><div class="layout-content">
                                <ul class="list" id="upload_file_list">
                                </ul>
                            </div>
                        </div>
                        <hr>
                        <div class="layoutrow">
                            <div class="layout-title">备注</div><div class="layout-content" id="Remark"></div>
                        </div>
                        <hr>
                    </div>
                </div>
                <div class="bottom">
                    <div class="button-container">
                        @if (ViewBag.AccessUpdate)
                        {
                             <button class="pear-btn pear-btn-primary pear-btn-md" id="btn_1_Update"><i class="layui-icon layui-icon-edit"></i>修改</button>
                        }
                        @if (ViewBag.AccessDelete)
                        {
                              <button class="pear-btn pear-btn-danger pear-btn-md" id="btn_1_Delete" lay-event="Delete">
                            <i class="layui-icon layui-icon-delete"></i>
                            删除
                        </button>
                        }
                       
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


@section scripts{
    <script>
                layui.use([ 'form', 'lscom' , 'dtree'], function () {
                    let dtree = layui.dtree;
                    let form = layui.form;
                    let $ = layui.jquery;
                    let lscom = layui.lscom;
                    let MODULE_PATH = "/Systems/Organize/";
                    let parentId = 0;

                    let TreeFuzzySearch= dtree.render({
                        elem: "#organization-tree",
                        initLevel: "10",
                        line: true,
                        ficon: ["1", "-1"],
                        icon: ["0", "2"],
                        method: 'get',
                        url: MODULE_PATH + "GetOrganizeDtree",
                        response: {
                    message: "msg",
                            statusCode: 0,
                        },
                        none: "没有数据",
                        dataStyle: "layuiStyle",
                        dataFormat: "list",
                        done: function (res, $ul, first) {
                       }
                });

                    dtree.on("node(organization-tree)", function (obj) {
                        if (obj.parentParam && obj.parentParam.context) {
                            $("#ParentTitle").val(obj.parentParam.context);
                        }
                        else {
                            $("#ParentTitle").val("");
                        }
                        if (parseInt( obj.param.nodeId )== 0) return false;
                        if (obj.param) {
                            let waitIndex = parent.layer.load(2);
                            lscom.ajax({
                                url: MODULE_PATH + 'GetModel' + lscom.utils.formatString("?id={0}", obj.param.nodeId),
                                type: 'get',
                                lsHandleError: false
                            }).done(function (data) {
                                if (data.code == 0) {
                                    $("#OrgName").text(data.data.orgName);
                                    $("#OrgName").next().remove();
                                    if (data.data.isenable) {
                                        $("#OrgName").after('&nbsp;&nbsp;<span class="layui-badge layui-bg-green">启用</span>');
                                    } else {
                                        $("#OrgName").after('&nbsp;&nbsp;<span class="layui-badge">停用</span>');
                                    }
                                   
                                    $("#OrgCode").text(data.data.orgCode);
                                    $("#OrgCompanyName").text(data.data.orgCompanyName);
                                    $("#Corporate").text(data.data.corporate);
                                    $("#TelephoneContact").text(data.data.contact + " " + data.data.telephone );
                                    $("#TelephoneContact1").text((data.data.contact1 == null ? "" : data.data.contact1) + " " + (data.data.telephone1 == null ? "" : data.data.telephone1));
                                    $("#TelephoneContact2").text((data.data.ontact2 == null ? "" : data.data.contact2) + " " + (data.data.telephone2 == null ? "" : data.data.telephone2) );
                                    $("#Addr").text(data.data.province + data.data.city + data.data.county + data.data.addr);
                                    if (data.data.fileList && data.data.fileList.length > 0) {
                                        $('#upload_file_list').empty();
                                        var liupload = '';
                                        for (var i = 0; i < data.data.fileList.length; i++) {
                                            var liupload = ' <li class="list-item">'
                                                + '<a href="' + data.data.fileList[i].fpath + '" target="_blank">' + data.data.fileList[i].fname+'</a>'
                                                      + '</li>';
                                        }
                                        $('#upload_file_list').append(liupload);
                                    }
                                    $('#Remark').text(data.data.remark);
                                }
                            }).fail(function (message) {
                                lscom.notify.error(message);
                            }).always(function () {
                                parent.layer.close(waitIndex);
                            });
                        }
                        parentId = obj.param.nodeId;
                    });

                    $("#btn_TreeFuzzySearch").click(function () {
                        var input = $("input[name='orgname']").val();
                        // 调用内置函数搜索节点
                        TreeFuzzySearch.fuzzySearch(input);
                        if ($("#organization-tree>li").hasClass('layui-hide') ) {
                            $("#organization-tree-empty").removeClass("layui-hide");
                        } else {
                            $("#organization-tree-empty").addClass("layui-hide");
                        }
                    });
                    $("#btn_0_Add").on("click", function () {
                    window.add(parentId);
                    });

                    $("#btn_1_Update").on("click", function () {
                        if (parentId > 0) {
                    window.edit(parentId);
                        } else {
                    parent.layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                        }
                    });
                    $("#btn_1_Delete,#btn_0_Delete").on("click", function () {
                        if (parentId > 0) {
                    window.remove(parentId);
                        } else {
                    parent.layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                        }
                    });

                    window.add = function (id) {
                    parent.layer.open({
                        type: 2,
                        title: '新增部门',
                        shade: 0.1,
                        area: ['900px', '650px'],
                        content: MODULE_PATH + 'CreateOrg' + lscom.utils.formatString("?parentId={0}", id),
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            parent.window['layui-layer-iframe' + index].submitForm();
                        }
                    });
                    }
                    window.edit = function (id) {
                    parent.layer.open({
                        type: 2,
                        title: '修改部门',
                        shade: 0.1,
                        area: ['900px', '650px'],
                        content: MODULE_PATH + 'EditOrg' + lscom.utils.formatString("?id={0}", id),
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            parent.window['layui-layer-iframe' + index].submitForm();
                        }
                    });
                    }

                    window.remove = function (data) {
                    parent.layer.confirm('确定删除吗?', {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        parent.layer.close(index);
                        let waitIndex = parent.layer.load(2);
                        lscom.ajax({
                            url: MODULE_PATH + 'DelOrg',
                            data: JSON.stringify({ "ids": data }),
                            lsHandleError: false
                        }).done(function (data) {
                            if (data.code == 0) {
                                lscom.notify.success(data.message);
                                dtree.reload("organization-tree");
                            }
                        }).fail(function (message) {
                            lscom.notify.error(message);
                        }).always(function () {
                            parent.layer.close(waitIndex);
                        });
                    });
                    }
                    window.saveCallback = function (data) {
                    parent.layer.close(data.index);
                        lscom.notify.success(data.message);
                        dtree.reload("organization-tree");
                    }
                    window.refresh = function () {
                        dtree.reload("organization-tree");
                    }
                });
    </script>
}
